package com.sx.pipeline.ui.setting.update

import android.content.Intent
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.util.ToastUtils
import com.sx.mvvmlibs.base.NoVMBaseActivity
import com.sx.pipeline.BR
import com.sx.pipeline.R
import com.sx.pipeline.app.base.CYDataBindingBaseActivity
import com.sx.pipeline.arouth.RoutePath
import com.sx.pipeline.databinding.ActNickOrSuperiorBinding
import com.sx.pipeline.ui.setting.profile.ProfileVM


/**
 * @Author: YY
 * @Date: 2022/4/5
 * @Description: 修改昵称/上级
 */
@Route(path = RoutePath.Setting.UPDATENICK)
class UpdateNickActivity :
    CYDataBindingBaseActivity<ActNickOrSuperiorBinding,ProfileVM>(R.layout.act_nick_or_superior), View.OnClickListener {
    @Autowired(name = "type")
    lateinit var type: String //1修改昵称 2修改直属上级
    @Autowired(name = "name")
    lateinit var name: String


    override fun initData() {
        super.initData()
        mBinding.setVariable(BR.onClick, this)
        mBinding.titleBar.leftView.setOnClickListener {
            finish()
        }
        mBinding.etInput.setText(name)
        when (type) {
            "1" -> mBinding.titleBar.title = getString(R.string.txt_change_nickname)
            "2" -> mBinding.titleBar.title = getString(R.string.txt_change_direct_superior)
        }
    }

    override fun onClick(v: View?) {
        when (v?.id) {
            R.id.tv_keep -> {
                if (TextUtils.isEmpty(mBinding.etInput.text.toString())){
                    ToastUtils.showShort("保存内容不可为空")
                    return
                }
                val intent = Intent()
                intent.putExtra("name", mBinding.etInput.text.toString())
                setResult(RESULT_OK, intent)
                finish()
            }
        }
    }

}